<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="../css/pintuer.css">
<link rel="stylesheet" href="../css/admin.css">
<script src="../js/jquery.js"></script>
<script src="../js/pintuer.js"></script>
<script src="../js/layer/layer.js"></script>
</head>
<body>
<form method="post" action="" id="listform">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 广告列表</strong> </div>
    <div class="padding border-bottom">
		<ul class="search" style="padding-left:10px;">
			<li> <a class="button border-main icon-plus-square-o" href="${ctx }/serve/advertisingForm.jsp"> 添加内容</a> </li>
        </ul>
    </div>
    <table class="table table-hover text-center">
      <tr>
        <th>ID</th>
		<th>标题</th>
        <th>内容</th>
		<th width="25%;">链接</th>
		<th>位置</th>
        <th>描述</th>
        <th>显示</th>
		<th>创建时间</th>
        <th width="250">操作</th>
      </tr>  		 
         <c:forEach items="${advertisingList }" var="advertising">
         	<tr>
	          <td>${advertising.id }</td>
			  <td>${advertising.title }</td>
	          <td class="textOrImageId" title="${advertising.image}">
				<img src="${advertising.image }" style="width:150px;">
			  </td>
			  <td>${advertising.link }</td>
			  <td>
			  	
			  	<c:if test="${advertising.location == 'home-top'}">
			  		首页顶部
			  	</c:if>
			  	<c:if test="${advertising.location == 'home-line'}">
			  		首页信息列表
			  	</c:if>
			  	<c:if test="${advertising.location == 'issue-center'}">
			  		问题与回答间
			  	</c:if>
			  	<c:if test="${advertising.location == 'issue-bottom'}">
			  		全部回答结尾
			  	</c:if>
			  </td>
	          <td>${advertising.describe }</td>
	          <td>
	          	<input type="checkbox"  <c:if test='${advertising.status==1}'>checked</c:if> onclick="isShow('${advertising.location }',${advertising.status} ,${advertising.id })"/>
			  </td>
			  <td>${advertising.createDateFormat }</td>
	          <td>
	          	<div class="button-group"> 
	          		<a class='button border-main' href='${ctx }/advertising/findById?id=${advertising.id}'><span class='icon-edit'></span> 修改</a>
	          		<a class="button border-red" href="javascript:void(0);" onclick="return del(${advertising.id})"><span class="icon-trash-o"></span> 删除</a>
	          	</div>
	          </td>
	        </tr>
         </c:forEach> 
    </table>
  </div>
</form>
<script type="text/javascript">
$(function (){
	$(".textOrImageId").each(function(){
		var text = $(this).attr("title");
		if(text.indexOf("www.saibaibu.com")!=-1){
			$(this).html('<img src="'+text+'" style="width:150px;">');
		}else{
			$(this).text(text);
		}
	})
})
//单个删除
function del(id){
	if(confirm("您确定要删除广告吗?")){
		window.location.href="${ctx }/advertising/delete?id="+id;
	}
}

function isShow(location,status,id){
	//alert(location+"  "+status+" "+id);
	if(confirm("您确定要更改显示状态吗?")){
		var i = 0;
		if(status==1){
			//alert("取消");
			i = 0;
		}else{
			//alert("显示");
			$.ajax({ 
			       type: "post", 
			       url: "${ctx}/advertising/updateStatus", 
			       async:false, 
			       data:"location="+location+"&status=0",
			       success: function(data){ 
			    	  // alert(data);
			       } 
				});
			i = 1;
		}
		$.ajax({ 
		       type: "post", 
		       url: "${ctx}/advertising/updateStatus", 
		       async:false, 
		       data:"id="+id+"&status="+i,
		       success: function(data){ 
		    	  // alert(data);
		       } 
			});
	}
	window.location="${ctx}/advertising/findAll";
}
</script>
</body>
</html>